package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.domain.query.FileQuery;
import com.winshare.saleAssistant.service.ArticleService;
import com.winshare.saleAssistant.service.FileManageService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/fileManage")
@CrossOrigin
@Api(value = "文章管理")
public class FileManageController {

    private final FileManageService fileManageService;

    public FileManageController(FileManageService fileManageService) {
        this.fileManageService = fileManageService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增资料库接口",notes = "新增资料库接口")
    public LogicResponse save(@RequestBody @Validated FileManageDTO fileManageDTO) {
        fileManageService.save(fileManageDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改资料库接口",notes = "修改资料库接口")
    public LogicResponse update(@RequestBody @Validated FileManageDTO fileManageDTO) {
        fileManageService.update(fileManageDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查看资料库详情")
    public LogicResponse getArticleDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(fileManageService.getFileDetail(baseIdDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除资料库接口",notes = "删除资料库接口")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        fileManageService.delete(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询资料库列表接口",notes = "查询文章列表接口")
    public LogicResponse queryFileList(@RequestBody @Validated fileQueryDTO fileQueryDTO) {
        return LogicResponse.success(fileManageService.getFileList(fileQueryDTO));
    }


}
